import sys
import utils
from user import User
from chapter import Chapter
import re
user = User()
def developing_tip():
    print("Developing...")
    utils.run_method_delay(main_menu)

def tutorial():
    developing_tip()

def submit_question():
    question = input("问题描述：")
    tip = input("注意事项：")
    yn = input("您的问题："+question+" 注意事项："+tip+" 确定吗？")
    print("提交完毕")
    utils.run_method_delay(main_menu)

def free_mod():
    developing_tip()

def chapter_mod():
    if not user.hasUser():
        user.getUser().newUser()

    name = user.getUser().name()
    while True:
        level = user.getUser().level()
        print('Hi，%s！接下来是第%d关！'%(name,level+1))
        chap = Chapter(level)
        print('题目：'+chap.question)
        print('注意事项：'+chap.tip)
        regex = input('请输入正则:')
        for test in chap.teststr:
            print(test)
            ret = re.match(regex,test[0],flags=0)
            if not (test[1] == (ret.group()!=None)):
                print(test[1],ret.group())
                print('失败，因为：',test,'没有匹配成功')
                break
                


        

def exit():
    print("Bye~")
    utils.run_method_delay(sys.exit)

def input_cus():
    return input("RegexPT # > ") 

def input_as_int():
    return int(input_cus())


main_menu_funcs = [chapter_mod,free_mod,submit_question,tutorial,exit]
def main_menu():
    print("\n=============================\nRegex Practice Prod. By LILPIG. >LEOSTUDIO<")
    print("\n1.闯关模式")
    print("2.自由模式")
    print("3.贡献题目")
    print("4.正则教程")
    print("5.退出\n")
    main_menu_funcs[input_as_int()-1]()

def start():
    welcome = "Hi,%s!Welcome to regex practice!"
    if user.getUser().name()!=None:
        print(welcome%user.getUser().name())
    else:
        print(welcome%"Baby")
    
    main_menu()
        